#ifndef __HT_LOG_H_
#define __HT_LOG_H_

#include <stdarg.h>

#ifdef HT_NOLOG

#define LOG 
#define LOGERR 

#else

#define LOG(msg, args...) do{ if(htlogflg) {                             \
    htlog(__FILE__, __LINE__, msg, ##args);                             \
    } }while(0)
#define LOGERR(msg, args...) do{ if(htlogflg){   errcode = errno;	\
    strncpy(errmsg, strerror(errcode), sizeof(errmsg));                 \
    errmsg[sizeof(errmsg)-1] = 0;			                \
    LOG(msg, errcode, errmsg, ##args);				        \
    } }while(0)

#endif /*HT_NOLOG*/


extern int htlogflg;
extern FILE * logfile;
extern int errcode;
extern char errmsg[256];

int htlog_init(char * fn);

void htlog(char * fn, int ln, char * msg,...);

#endif /*__HT_LOG_H_*/
